var constants = require('./constants');

var SESSION_TOKEN_KEY = 'weapp_session_' + constants.WX_SESSION_TOKEN;
var SESSION_USER_KEY = 'weapp_session_' + constants.WX_SESSION_USER_INFO;
var SESSION_PERMI_KEY = 'weapp_session_' + constants.WX_SESSION_PERMI;
var SESSION_ROLE_KEY = 'weapp_session_' + constants.WX_SESSION_ROLE;

var Session = {
    get: function () {
        return wx.getStorageSync(SESSION_TOKEN_KEY) || null;
    },
    set: function (session) {
        wx.setStorageSync(SESSION_TOKEN_KEY, session);
    },

    // 用户信息
    getUser: function () {
        return wx.getStorageSync(SESSION_USER_KEY) || null;
    },
    setUser: function (session) {
        wx.setStorageSync(SESSION_USER_KEY, session);
    },

    // 权限
    getPermi: function () {
        return wx.getStorageSync(SESSION_PERMI_KEY) || null;
    },
    setPermi: function (session) {
        wx.setStorageSync(SESSION_PERMI_KEY, session);
    },

    // 角色
    getRole: function () {
        return wx.getStorageSync(SESSION_ROLE_KEY) || null;
    },
    setRole: function (session) {
        wx.setStorageSync(SESSION_ROLE_KEY, session);
    },

    clear: function () {
        wx.removeStorageSync(SESSION_TOKEN_KEY);
        wx.removeStorageSync(SESSION_USER_KEY);
        wx.removeStorageSync(SESSION_PERMI_KEY);
        wx.removeStorageSync(SESSION_ROLE_KEY);
    },

};
module.exports = Session;
